/// 打印数组的线程
package threds;

import Bricks.Core;
import Tool.intArrayTool;
import com.sun.jna.platform.win32.Guid;
import org.omg.CORBA.CODESET_INCOMPATIBLE;

import java.util.Random;

public class Print implements Runnable{
    static  int modelofNmber ;  //游戏模式
    public Print(int modelofNmber){
        this.modelofNmber = modelofNmber;
    }

    @Override
    public void run() {
        while(Core.threadDeath == 1){
            caozuo();
        }
    }
    public void caozuo(){
        //休闲模式
        if(modelofNmber == 1){
            if(Thread.currentThread().getName().equals("打印")){
                //print();  //单纯打印二维数组
                printTetris();  //脱离二维数组形态
                //printAll();  //打印所有
            }
            else if(Thread.currentThread().getName().equals("结束检查")){
                endInspection();
            }
            else if(Thread.currentThread().getName().equals("预判制造")){
                Core.movingArrayAnticipation = creatAnticipation(Core.movingArray);
            }
            else {
                handing();
                try{
                    Thread.sleep(750);  //搬运一秒执行一次
                }
                catch (InterruptedException e){
                }
            }
        }
        //基础模式
        if(modelofNmber == 2){
            if(Thread.currentThread().getName().equals("打印")){
                //print();  //单纯打印二维数组
                printTetris();  //脱离二维数组形态
                //printAll();  //打印所有
            }
            else if(Thread.currentThread().getName().equals("结束检查")){
                endInspection();
            }
            else if(Thread.currentThread().getName().equals("预判制造")){
                Core.movingArrayAnticipation = creatAnticipation(Core.movingArray);
            }
            else {
                handing();
                //每200分，快50毫秒
                int myMillis = 750 - Core.score/200*50;
                if(myMillis<100) myMillis = 100;
                try{
                    Thread.sleep(myMillis);  //搬运速度会改变
                }
                catch (InterruptedException e){
                }
            }
        }
        //疯狂模式
        if(modelofNmber == 3){
            if(Thread.currentThread().getName().equals("打印")){
                //print();  //单纯打印二维数组
                printTetris();  //脱离二维数组形态
                //printAll();  //打印所有
            }
            else if(Thread.currentThread().getName().equals("结束检查")){
                endInspection();
            }
            else if(Thread.currentThread().getName().equals("预判制造")){
                Core.movingArrayAnticipation = creatAnticipation(Core.movingArray);
            }
            else {
                handing();
                try{
                    Thread.sleep(100);  //直接一直100毫秒
                }
                catch (InterruptedException e){
                }
            }
        }
        //隐身模式
        if(modelofNmber == 4){
            if(Thread.currentThread().getName().equals("打印")){
                //print();  //单纯打印二维数组
                //printTetris();  //脱离二维数组形态
                //printAll();  //打印所有
                printTetrisStealth();  //隐身模式的打印
            }
            else if(Thread.currentThread().getName().equals("结束检查")){
                endInspection();
            }
            else if(Thread.currentThread().getName().equals("预判制造")){
                Core.movingArrayAnticipation = creatAnticipation(Core.movingArray);
            }
            else {
                handing();
                try{
                    Thread.sleep(750);  //一直750毫秒
                }
                catch (InterruptedException e){
                }
            }
        }
        //疯狂隐身模式
        if(modelofNmber == 5){
            if(Thread.currentThread().getName().equals("打印")){
                //print();  //单纯打印二维数组
                //printTetris();  //脱离二维数组形态
                //printAll();  //打印所有
                printTetrisStealth();  //隐身模式的打印
            }
            else if(Thread.currentThread().getName().equals("结束检查")){
                endInspection();
            }
            else if(Thread.currentThread().getName().equals("预判制造")){
                Core.movingArrayAnticipation = creatAnticipation(Core.movingArray);
            }
            else {
                handing();
                try{
                    Thread.sleep(100);  //一直100毫秒
                }
                catch (InterruptedException e){
                }
            }
        }
        //倒立模式
        if(modelofNmber == 6){
            if(Thread.currentThread().getName().equals("打印")){
                //print();  //单纯打印二维数组
                //printTetris();  //脱离二维数组形态
                //printAll();  //打印所有
                //printTetrisStealth();  //隐身模式的打印
                printTetrisHandstand();  //倒立打印
            }
            else if(Thread.currentThread().getName().equals("结束检查")){
                endInspection();
            }
            else if(Thread.currentThread().getName().equals("预判制造")){
                Core.movingArrayAnticipation = creatAnticipation(Core.movingArray);
            }
            else {
                handing();
                try{
                    Thread.sleep(750);  //一直750毫秒
                }
                catch (InterruptedException e){
                }
            }
        }

    }
    /*打印的方法
    *改变策略，不再单纯的打印二维数组，
    * 新策略为：根据二维数组拼接出字符串，然后打印一次
     */
    public void print(){
            String tetris = "";
            for(int i =4;i < Core.twoArray.length; i++){  //前四行为方块出生点，不打印显示
                for(int j = 0; j < Core.twoArray[i].length; j++){
                    int number_n = 0;
                    String newline = "";
                    if(j == Core.twoArray[i].length-1) number_n = 1;  //一行的行末，添加标记
                    if(i == Core.twoArray.length-1 && j == Core.twoArray[i].length-1) number_n = 9;  //数组的尾巴
                    //这里只有到了行尾才会开始进入循环体
                    for(int y=0; y<number_n; y++){
                        if(i == 13) newline = "                                             " + Core.score;
                        newline += "\n";
                    }
                    String piece = "0";
                    if(Core.twoArray[i][j] == 1 ) piece = "1";
                    for(int w = 0; w < Core.movingArray.length-2; w ++){  //对于正在被操作的块，我们也设置为“1”
                        if(Core.movingArray[w] == i && Core.movingArray[w+1] == j ) piece = "1";
                        w ++;
                    }
                    tetris += piece +newline;
                }
            }
           System.out.print(tetris);
    }
    /*脱离二维数组形态的显示
     */
    public void printTetris(){
        String tetris = "";
        for(int i =4;i < Core.twoArray.length; i++){  //前四行为方块出生点，不打印显示
            for(int j = 0; j < Core.twoArray[i].length; j++){
                int number_n = 0;
                String newline = "";
                if(j == Core.twoArray[i].length-1) number_n = 1;
                if(i == Core.twoArray.length-1 && j == Core.twoArray[i].length-1) number_n = 9;
                for(int y=0; y<number_n; y++){
                    //夹带私货，把分数组到待打印的字符串里
                    if(i == 4) newline =  "|                                               AD左右移动，J快速下落，空格变形";
                    if(i == 5) newline =  "|                                               回车重开,模式：" + Core.modelofNmber;
                    if(i == 13) newline = "|                                             " + Core.score + "\n";
                    else {
                        newline += "|\n";
                    }
                }
                String piece = "  ";
                if(Core.twoArray[i][j] == 1 ) piece = "□";
                for(int w = 0; w < Core.movingArray.length-2; w ++){  //对于正在被操作的块，我们也设置为“1”
                    if(Core.movingArray[w] == i && Core.movingArray[w+1] == j ) piece = "□";
                    if(Core.movingArrayAnticipation[w] == i && Core.movingArrayAnticipation[w+1] == j ) piece = "■";  //预判
                    w ++;
                }
                tetris += piece +newline;
            }
        }
        System.out.print(tetris);
    }
    /*脱离二维数组形态的显示，专注隐身模式
     */
    public void printTetrisStealth(){
        String tetris = "";
        for(int i =4;i < Core.twoArray.length; i++){  //前四行为方块出生点，不打印显示
            for(int j = 0; j < Core.twoArray[i].length; j++){
                int number_n = 0;
                String newline = "";
                if(j == Core.twoArray[i].length-1) number_n = 1;
                if(i == Core.twoArray.length-1 && j == Core.twoArray[i].length-1) number_n = 9;
                for(int y=0; y<number_n; y++){
                    //夹带私货，把分数组到待打印的字符串里
                    if(i == 4) newline =  "|                                               AD左右移动，J快速下落，空格变形";
                    if(i == 5) newline =  "|                                               回车重开,模式：" + Core.modelofNmber;
                    if(i == 13) newline = "|                                             " + Core.score + "\n";
                    else {
                        newline += "|\n";
                    }
                }
                String piece = "  ";
                if(Core.twoArray[i][j] == 1 ) piece = "  ";
                for(int w = 0; w < Core.movingArray.length-2; w ++){  //对于正在被操作的块，我们也设置为“1”
                    if(Core.movingArray[w] == i && Core.movingArray[w+1] == j ) piece = "□";
                    if(Core.movingArrayAnticipation[w] == i && Core.movingArrayAnticipation[w+1] == j ) piece = "■";  //预判
                    w ++;
                }
                tetris += piece +newline;
            }
        }
        System.out.print(tetris);
    }
    /*脱离二维数组形态的显示，倒立打印
     */
    public void printTetrisHandstand(){
        String tetris = "";
        for(int i =23;i > 3; i--){  //前四行为方块出生点，不打印显示
            for(int j = 0; j < Core.twoArray[i].length; j++){
                int number_n = 0;
                String newline = "";
                if(j == Core.twoArray[i].length-1) number_n = 1;
                if(i == 4 && j == Core.twoArray[i].length-1)
                    number_n = 9;
                for(int y=0; y<number_n; y++){
                    //夹带私货，把分数组到待打印的字符串里
                    if(i == 23) newline =  "|                                               AD左右移动，J快速下落，空格变形";
                    if(i == 22) newline =  "|                                               回车重开,模式：" + Core.modelofNmber;
                    if(i == 13) newline = "|                                             " + Core.score + "\n";
                    else {
                        newline += "|\n";
                    }
                }
                String piece = "  ";
                if(Core.twoArray[i][j] == 1 )
                    piece = "□";
                for(int w = 0; w < Core.movingArray.length-2; w ++){  //对于正在被操作的块，我们也设置为“1”
                    if(Core.movingArray[w] == i && Core.movingArray[w+1] == j )
                        piece = "□";
                    if(Core.movingArrayAnticipation[w] == i && Core.movingArrayAnticipation[w+1] == j )
                        piece = "■";  //预判
                    w ++;
                }
                tetris += piece +newline;
            }
        }
        System.out.print(tetris);
    }
    /*打印出所有的数组，包括出生地的四行*/
    public void printAll(){
        String tetris = "";
        for(int i =0;i < Core.twoArray.length; i++){  //前四行为方块出生点，不打印显示
            for(int j = 0; j < Core.twoArray[i].length; j++){
                int number_n = 0;
                String newline = "";
                if(j == Core.twoArray[i].length-1) number_n = 1;  //一行的行末，添加标记
                if(i == Core.twoArray.length-1 && j == Core.twoArray[i].length-1) number_n = 5;  //数组的尾巴
                //这里只有到了行尾才会开始进入循环体
                for(int y=0; y<number_n; y++){
                    if(i == 13) newline = "                                             " + Core.score;
                    newline += "\n";
                }
                String piece = "0";
                if(Core.twoArray[i][j] == 1 ) piece = "1";
                for(int w = 0; w < Core.movingArray.length-2; w ++){  //对于正在被操作的块，我们也设置为“1”
                    if(Core.movingArray[w] == i && Core.movingArray[w+1] == j ) piece = "1";
                    if(Core.movingArrayAnticipation[w] == i && Core.movingArrayAnticipation[w+1] == j ) piece = "1";
                    w ++;
                }
                tetris += piece +newline;

            }
            if(i == 3) tetris +="------------------------\n";
        }
        System.out.print(tetris);
    }

    /*搬运的方法，即方块的自动下落*/
    public void handing(){
        if(Core.threadDeath == 0) return;  //结束
        //如果不能下移动了就开始填充
        if(!canMoveDown()) {
            if(updateForAll()){  //如果满足填充条件
                int rowNumber = eliminate(Core.twoArray);  //查看消除,同时返回消除的行数
                Core.score = Core.scoring(Core.score,rowNumber);  //更新分数
                Core.movingArray = createNewCube(randomNumber(0,18));  //新方块产生
                //Core.movingArray = createNewCube(5);  //新方块产生
                //Core.movingArray = createNewCube(Core.movingArray);  //新方块产生
                handing();//搬运
            }
        }
        //否则，继续下移
        else {
            //这里的方法没有权限改变数组尾部的值
            for(int i = Core.movingArray.length -2; i > -1; i --) {
                if (i % 2 != 0) continue;  //奇数索引值代表横坐标
                Core.movingArray[i]++;  //纵坐标加1
            }
            if(updateForAll()){  //如果满足填充条件
                int rowNumber = eliminate(Core.twoArray);  //查看消除
                Core.score = Core.scoring(Core.score,rowNumber);  //更新分数
                Core.movingArray = createNewCube(randomNumber(0,18));  //新方块产生
                //Core.movingArray = createNewCube(5);  //新方块产生
                //Core.movingArray = createNewCube(Core.movingArray);  //新方块产生
                handing();//搬运
            }

        }

        //不同形状的方块，它们具有不同的填充判定条件（在这里，把方块停止运动，理解为往数组填充‘1’）
        //先废弃这种写法,对于计算机的快速运算能力,而且俄罗斯方块中最复杂的,最大的形状,至多也就进行大约8次运算
        //如果追求极致的效率,嗯,付出的东西,与得到的速度提升,可谓是杀鸡用牛刀
//        switch (Core.movingArray[Core.movingArray.length - 1]){
//            case 0:
//                if(updateForSquare()){
//                    Core.movingArray = createNewCube(0);  //新方块产生
//                    handing();//搬运
//                }
//                break;
//            default:
//                break;
//        }




    }
    //新方块的出生
    public int[] createNewCube(int cubeCode){
        int [] itemArray = new int[9];
        switch(cubeCode){
            case 0:  //正方形
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 3;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 0; //0标识方块为正方形
                break;
            case 1:
                itemArray[0] = 0;
                itemArray[1] = 4;
                itemArray[2] = 1;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 1; //1标识方块为竖直长条
                break;
            case 2:
                itemArray[0] = 3;
                itemArray[1] = 3;
                itemArray[2] = 3;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 6;
                itemArray[8] = 2; //2标识方块为横向长条
                break;
            case 3:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 3; //3标识方块为Z形
                break;
            case 4:
                itemArray[0] = 1;
                itemArray[1] = 5;
                itemArray[2] = 2;
                itemArray[3] = 5;
                itemArray[4] = 2;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 4; //4标识方块为竖直Z形
                break;
            case 5:
                itemArray[0] = 2;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 5;
                itemArray[4] = 3;
                itemArray[5] = 3;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 5; //5标识方块为反向Z形
                break;
            case 6:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 6; //6标识方块为竖直反向Z形
                break;
            case 7:
                itemArray[0] = 2;
                itemArray[1] = 4;
                itemArray[2] = 3;
                itemArray[3] = 3;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 7; //7标识方块为凸形
                break;
            case 8:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 8; //8标识方块为右向凸形
                break;
            case 9:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 9; //9标识方块为下向凸形
                break;
            case 10:
                itemArray[0] = 1;
                itemArray[1] = 5;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 10; //10标识方块为左向凸形
                break;
            case 11:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 11; //11标识方块为L形
                break;
            case 12:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 3;
                itemArray[8] = 12; //12标识方块为下向L形
                break;
            case 13:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 1;
                itemArray[3] = 5;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 13; //13标识方块为左向L形
                break;
            case 14:
                itemArray[0] = 2;
                itemArray[1] = 5;
                itemArray[2] = 3;
                itemArray[3] = 3;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 14; //14标识方块为上向L形
                break;
            case 15:
                itemArray[0] = 1;
                itemArray[1] = 5;
                itemArray[2] = 2;
                itemArray[3] = 5;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 15; //15标识方块为翻转L形
                break;
            case 16:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 3;
                itemArray[3] = 3;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 16; //16标识方块为上向翻转L形
                break;
            case 17:
                itemArray[0] = 1;
                itemArray[1] = 3;
                itemArray[2] = 1;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 17; //17标识方块为右向翻转L形
                break;
            default:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 18; //18标识方块为下向翻转L形
        }

        return itemArray;
    }
    //新方块的出生
    public int[] createNewCube(int[] cubeCode){
        int [] itemArray = new int[9];
        switch(cubeCode[cubeCode.length -1]){
            case 0:  //正方形
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 3;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 0; //0标识方块为正方形
                break;
            case 1:
                itemArray[0] = 0;
                itemArray[1] = 4;
                itemArray[2] = 1;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 1; //1标识方块为竖直长条
                break;
            case 2:
                itemArray[0] = 3;
                itemArray[1] = 3;
                itemArray[2] = 3;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 6;
                itemArray[8] = 2; //2标识方块为横向长条
                break;
            case 3:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 3; //3标识方块为Z形
                break;
            case 4:
                itemArray[0] = 1;
                itemArray[1] = 5;
                itemArray[2] = 2;
                itemArray[3] = 5;
                itemArray[4] = 2;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 4; //4标识方块为竖直Z形
                break;
            case 5:
                itemArray[0] = 2;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 5;
                itemArray[4] = 3;
                itemArray[5] = 3;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 5; //5标识方块为反向Z形
                break;
            case 6:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 6; //6标识方块为竖直反向Z形
                break;
            case 7:
                itemArray[0] = 2;
                itemArray[1] = 4;
                itemArray[2] = 3;
                itemArray[3] = 3;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 7; //7标识方块为凸形
                break;
            case 8:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 8; //8标识方块为右向凸形
                break;
            case 9:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 9; //9标识方块为下向凸形
                break;
            case 10:
                itemArray[0] = 1;
                itemArray[1] = 5;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 10; //10标识方块为左向凸形
                break;
            case 11:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 11; //11标识方块为L形
                break;
            case 12:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 3;
                itemArray[8] = 12; //12标识方块为下向L形
                break;
            case 13:
                itemArray[0] = 1;
                itemArray[1] = 4;
                itemArray[2] = 1;
                itemArray[3] = 5;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 13; //13标识方块为左向L形
                break;
            case 14:
                itemArray[0] = 2;
                itemArray[1] = 5;
                itemArray[2] = 3;
                itemArray[3] = 3;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 14; //14标识方块为上向L形
                break;
            case 15:
                itemArray[0] = 1;
                itemArray[1] = 5;
                itemArray[2] = 2;
                itemArray[3] = 5;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 15; //15标识方块为翻转L形
                break;
            case 16:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 3;
                itemArray[3] = 3;
                itemArray[4] = 3;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 16; //16标识方块为上向翻转L形
                break;
            case 17:
                itemArray[0] = 1;
                itemArray[1] = 3;
                itemArray[2] = 1;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 4;
                itemArray[6] = 3;
                itemArray[7] = 4;
                itemArray[8] = 17; //17标识方块为右向翻转L形
                break;
            default:
                itemArray[0] = 2;
                itemArray[1] = 3;
                itemArray[2] = 2;
                itemArray[3] = 4;
                itemArray[4] = 2;
                itemArray[5] = 5;
                itemArray[6] = 3;
                itemArray[7] = 5;
                itemArray[8] = 18; //18标识方块为下向翻转L形
        }

        return itemArray;
    }
    //正方形方块的填充判定条件
    public boolean updateForSquare(){
        boolean completed = false;
        if(Core.movingArray[6] == Core.twoArray.length-1
                || Core.twoArray[Core.movingArray[6] + 1][Core.movingArray[7]] == 1
                || Core.twoArray[Core.movingArray[4] + 1][Core.movingArray[5]] == 1
                ){  //判定边界,满足条件即定格方块
            for(int i = 0; i < Core.movingArray.length-1; i ++){
                if(i%2 != 0) continue;
                Core.twoArray[Core.movingArray[i]][Core.movingArray[i+1]] = 1;
            }
            completed = true;
        }
        return completed;
    }
    //针对所有形状方块的填充函数
    // 一通百通的野蛮写法（唯一一个优化就是，我从后面开始遍历数组，稍微提升一些效率）
    public boolean updateForAll(){
        boolean completed = false;
        for(int i = Core.movingArray.length-3; i > -1; i --){
            if(i%2 != 0) continue;  //横坐标不管
            if(Core.movingArray[i] == Core.twoArray.length -1
                    || Core.twoArray[Core.movingArray[i] + 1][Core.movingArray[i+1] ]== 1
            )
            {

                //填充
                //填充顺序应为从下到上
                for(int j = Core.movingArray.length-3 ; j > -1 ; j --){
                    if(j%2 != 0) continue;

                    Core.twoArray[Core.movingArray[j]][Core.movingArray[j+1]] = 1;
                    if(Core.movingArray[j] < 4) return false;

                }
                completed = true;
                break;
            }

        }

        return completed;
    }
    //争对整个二维数组的消除，我希望降低一些对Core.twoArray的耦合
    //处理好数组之后，它要返回一下消除的行数，方便后续的处理
    //不得，这个算法越写越复杂了
    public int eliminate(int[][] pendingArray){
        int[] scoreTemplate = new int[10];  //得分模板
        int[] blankTemplate = new int[10];  //空白模板
        int changeNumber = 0;  //缺省0行
        //填充分数，空白两个模板值
        for(int i = 0; i < 10 ; i++){
            scoreTemplate[i] = 1;
            blankTemplate[i] = 0;
        }
        int[][] proceedArray = new int[pendingArray.length][pendingArray[0].length];  //进行处理的数组
        System.arraycopy(pendingArray,0,proceedArray,0,proceedArray.length);
        int numberRow = 0;  //用来统计消除的行数
        int indexRow  = 0;  //用来消除起始行索引
        ///一种特殊情况，例如：1234行，23行不满足消除条件，那么就要做到只消除14行，用这个记下23行索引值
        ///我又改主意了，这个这样来搞，比如检查1234行，1行可以消除，[0]=1; 2行不能消除,[1]=0; 3行不能消除,[2]=0; 4行能消除，[3]=1
        int [] specialRowIndexs = new int[4];
        int specialRowNmber = 4;
        //用来了解数组的消除情况，每次了解，其实就两种情况，有消除的，没有消除的
        for(int i = proceedArray.length -1; i > 3; i--){
            //有可以消除的行
            if(intArrayTool.isSame(proceedArray[i],scoreTemplate)){
                numberRow = 1;
                indexRow = i;
                specialRowIndexs[0] = 1;
                specialRowNmber --;
                //至多一次消除4行，即每次最多检查四行
                //意思也可以是，每次都检查四行
                for(int j = 1; j < 4; j ++){
                    if(intArrayTool.isSame(proceedArray[i-j],scoreTemplate)){
                        numberRow ++;
                        specialRowIndexs[j] = 1;
                        specialRowNmber --;
                    }
                }
                break;
            }
            if(intArrayTool.isSame(pendingArray[i],blankTemplate)) break;  //这里只是为了尽早结束循环，并非是情况分类的一种
        }
        ///了解完情况之后,开始针对两种情况进行处理
        //没有可以消除的
        if(numberRow == 0){
            return changeNumber;  //返回0
        }
        //有可以消除的
        else {
            //先处理一个东西，先把将要被消除的数组集中到一起
            for(int i = 0 ; i < 4; i ++){
                if(specialRowIndexs[i] == 1){
                    for(int j = i +1; j < 4; j ++){
                        if (specialRowIndexs[j] == 0){
                            int item = -1;  //中间变量
                            int itemArray [] = new int[10];
                            item = specialRowIndexs[i];
                            itemArray = proceedArray[indexRow - i];
                            specialRowIndexs[i] = specialRowIndexs[j];
                            proceedArray[indexRow - i] = proceedArray[indexRow - j];
                            specialRowIndexs[j] = item;
                            proceedArray[indexRow -j] = itemArray;
                            break;
                        }
                    }
                }

            }
          indexRow = indexRow - specialRowNmber ;
            for(int i = indexRow; i > 3; i --){
                    proceedArray[i] = new int[proceedArray[i].length];  //可以消除行先置为000000；
                    int k = i - numberRow;
                    if(k < 4) continue;
                    proceedArray[i] = pendingArray[k];

            }
            System.arraycopy(proceedArray,0,pendingArray,0,pendingArray.length);
            changeNumber = numberRow;
            return changeNumber;  //返回处理的行数
            //eliminate(pendingArray); //应该不会消除四行以上的，对的，就是不会
        }

    }
    //游戏结束检查
    public void endInspection(){

        for(int i = 0; i < Core.twoArray[4].length; i ++){
            if(Core.twoArray[4][i] == 1) {
                Core.threadDeath = 0;
                System.out.println("结束,得分：" + Core.score + "。 按回车重新开始游戏");
                break;
            }
        }

    }
    /*方块的急速下降，理想高效的办法，应该是，当你按下指定的下移键，那么这个移动中的方块，就直接跳跃到当前的底部
     * 那么，这个跳跃后的坐标数据，就显得尤为重要了，那怎么得出这个跳跃后的坐标呢？
     * 哦，应该这样，在方法里模拟当前方块的快速下落*/
    public static int[] creatAnticipation(int [] movingArray){
        int temporaryArray [] = arrayCopy(movingArray);  //临时存放
        //至多模拟21次
        for(int i = 0; i < 21; i ++){
            //先弄出模拟值
            for(int j = 0; j < temporaryArray.length-1;j ++){
                if(j%2 != 0 )continue;
                temporaryArray[j]++;
            }
            //检查模拟值的合理
            for(int k = 0; k < temporaryArray.length - 2; k ++){
                if(k%2 !=0)continue;
                if(temporaryArray[k] == 24 || Core.twoArray[temporaryArray[k]][temporaryArray[k+1]] == 1){
                    //此时，坐标数据已为不合法数据，但是，现在只要往后退一纵坐标，即为最佳下落坐标
                    for(int f = 0; f < temporaryArray.length-1;f ++){
                        if(f%2 != 0 )continue;
                        temporaryArray[f]--;
                    }
                }
            }
        }
        return temporaryArray;  //目标完成，退出

    }
    //针对当前移动中方块是否能继续下移的判断
    public boolean canMoveDown(){
        boolean isCan = true;
        for(int i = Core.movingArray.length-3; i > -1; i --){
            if(i%2 != 0) continue;  //横坐标不管
            if(Core.movingArray[i] == Core.twoArray.length -1 || Core.twoArray[Core.movingArray[i] + 1][Core.movingArray[i+1] ]== 1 ){
                isCan = false;
                break;
            }

        }
        return isCan;
    }
    //获取指定区间内的随机数
    public int randomNumber(int min,int max){
       return (int) ((Math.random() * (max + 1 - min)) + min);
    }
    ///数组深复制
    public static int[] arrayCopy(int [] arrayOne){
        int [] arrayTwo = new int[arrayOne.length];
        System.arraycopy(arrayOne,0,arrayTwo,0,arrayTwo.length);
        return arrayTwo;
    }

}
